// @ts-ignore
/* eslint-disable */
import { request } from 'umi';



/** 获取当前的用户 GET /api/currentUser */
export async function currentUser(options?: { [key: string]: any }) {
  return request<{
    data: API.CurrentUser;
    //}>('/api/currentUser', {
    //}>('/api/antdcurrentUser', {
    //}>('http://127.0.0.1:8088/api/antdcurrentUser', {
  }>('http://greeshare.gree.com/v1/api/getuserinfo', {
 // }>('http://192.168.3.129:8088/v1/api/getuserinfo', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
  //return request<Record<string, any>>('/api/login/outLogin', {
  //return request<Record<string, any>>('/api/logout', {
  return request<Record<string, any>>('http://greeshare.gree.com/v1/api/logout', {
 // return request<Record<string, any>>('http://192.168.3.81:8088/v1/api/logout', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 登录接口 POST /api/login/account */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  //return request<API.LoginResult>('/api/login/account', {
  //return request<API.LoginResult>('/pub/testlogin', {
  return request<API.LoginResult>('http://greeshare.gree.com/v1/pub/login', {
//  return request<API.LoginResult>('http://192.168.3.129:8088/v1/pub/login', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 此处后端没有提供注释 GET /api/notices */
export async function getNotices(options?: { [key: string]: any }) {
  return request<API.NoticeIconList>('/api/notices', {
    method: 'GET',
    ...(options || {}),
  });
}

/** 获取规则列表 GET /api/rule */
export async function rule(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<API.RuleList>('/api/rule', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

/** 新建规则 PUT /api/rule */
export async function updateRule(options?: { [key: string]: any }) {
  return request<API.RuleListItem>('/api/rule', {
    method: 'PUT',
    ...(options || {}),
  });
}

/** 新建规则 POST /api/rule */
export async function addRule(options?: { [key: string]: any }) {
  return request<API.RuleListItem>('/api/rule', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 删除规则 DELETE /api/rule */
export async function removeRule(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/api/rule', {
    method: 'DELETE',
    ...(options || {}),
  });
}

// 数据用dayjs转化，不用加duration: 8h
export async function getGreeProductStatesByTimelongAngImsi(timelong: number, deviceImsi: string) {
  // let barcode = "123456789";
  // let deviceImsi = "46006304228299"
  let qin = `from(bucket: "yjy")
      |> range(start: -${timelong}h)
      |> filter(fn: (r) => r["_measurement"] == "zhuche")
      |> filter(fn: (r) => r["DeviceImsi"] == "${deviceImsi}")
      |> drop(columns: ["_measurement","Barcode","DeviceImsi","_start","_stop","result","table"])
      |> yield()
  `;
  return request<any>('http://greeshare.gree.com/v1/api/influx', {
  //return request<any>('http://192.168.3.81:8088/v1/api/influx', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      Oper: 'query', // 操作名称
      fluxstring: qin,
    },
  });
}



// 数据用dayjs转化，不用加duration: 8h
/* export async function dayjs_getGreeProductStates_temper(t: number, deviceImsi: string) {
  let qin = `from(bucket: "yjy")
      |> range(start: -${t}h)
      |> filter(fn: (r) => r["_measurement"] == "zhuche")
      |> filter(fn: (r) => r["DeviceImsi"] == "${deviceImsi}")
      |> filter(fn: (r) => r["_field"] == "Stemper_in" or r["_field"] == "Stemper_out" or r["_field"] == "Stemper_in_pipe" or r["_field"] == "Stemper_ex")
      |> drop(columns: ["_measurement","Barcode","_start","_stop","result","table"])
      |> yield()
  `;
  console.log(qin);
  return influx_request(qin);
} 
const influx_request = (qin: string) =>
  request<any>('http://192.168.3.81:8088/v1/api/influx', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      Oper: 'query', // 操作名称
      fluxstring: qin,
    },
  });
*/
export async function getGreeProductsFromDg(params: { [key: string]: any }) {
  const nodetype = 'GreeProduct';

  //greeproduct(func: type(GreeProduct)) @filter(eq(barcode, %q) and eq(deviceimsi, %q)){
  let qdg2: string = `{
      greeproducts(func: type(${nodetype})){
        uid
        devicetype
        devicemodel
        barcode
        deviceimsi
        online
        ttime
        deverr
      }
  }`;
  console.log('-----');
  console.log(params);
  console.log(qdg2);
  console.log('-----');

  return request<API.GreeProductList>('http://greeshare.gree.com/api/dgraph', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      Oper: 'query', // 操作名称
      Query: qdg2, // Query语法
      /*             params: {
              ...params,
            },
            ...(options || {}), */
    },
  });
}

export async function getGreeProductsFromMysql(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
    //sorter?: any,
    //filter?: any,
    options?: { [key: string]: any },
) {
  //console.log(params,sorter,filter)
  return request<API.GreeProductList>('http://greeshare.gree.com/v1/api/productList', {
  //return request<API.GreeProductList>('http://192.168.3.81:8088/v1/api/productList', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      //params: url 请求参数,这里是post 提交， 使用data
      //params: {
        ...params,
      //},
    // sorter,
    // filter,
     ...(options || {}),
    },
  });
}

export async function getGreeProductsFromMysql2(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
    //sorter?: any,
    //filter?: any,
    options?: { [key: string]: any },
) {
  //console.log(params,sorter,filter)
  return request<API.GreeProductList>('http://greeshare.gree.com/v1/api/productList', {
  //return request<API.GreeProductList>('http://192.168.3.81:8088/v1/api/productList', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      //params: url 请求参数,这里是post 提交， 使用data
      //params: {
        ...params,
      //},
    // sorter,
    // filter,
     ...(options || {}),
    },
  });
}


export async function getProductById(
    id: number
):Promise<API.GreeProductResp> {
  //console.log(params,sorter,filter)
  return request<API.GreeProductResp>('http://greeshare.gree.com/v1/api/getProductById', {
  //return request<API.GreeProductList>('http://192.168.3.81:8088/v1/api/product', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      //params: url 请求参数,这里是post 提交， 使用data
      //params: {
        id: id,
    },
  });
}


export async function getsubinfo(
  params: {
    userid?: number;
    productid?: number;
    phone?: string;
  },
    //sorter?: any,
    //filter?: any,
    options?: { [key: string]: any },
) {
  //console.log(params,sorter,filter)
  return request<API.ProductSub>('http://greeshare.gree.com/v1/api/getsubinfo', {
 // return request<API.ProductSubResp>('http://192.168.3.81:8088/v1/api/getsubinfo', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      //params: url 请求参数,这里是post 提交， 使用data
      //params: {
        ...params,
      //},
    // sorter,
    // filter,
     ...(options || {}),
    },
  });
}

export async function saveAndupdataProductSub(
  params: API.ProductSub
) {
  //console.log(params,sorter,filter)
  return request<API.GreeProductList>('http://greeshare.gree.com/v1/api/saveproductsub', {
 // return request<API.ProductSubResp>('http://192.168.3.81:8088/v1/api/saveproductsub', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: params,
  });
}


export async function getSubProductsByUid(
  params: {
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  //sorter?: any,
  //filter?: any,
  userid: number,
  options?: { [key: string]: any; },

): Promise<API.GreeSubProductList> {
  //console.log(params,sorter,filter)
  return request<API.GreeSubProductList>('http://greeshare.gree.com/v1/api/getSubProductsByUid', {
 // return request<API.GreeSubProductList>('http://192.168.3.129:8088/v1/api/getSubProductsByUid', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      //params: url 请求参数,这里是post 提交， 使用data
      //params: {
        ...params,
      //},
    // sorter,
    // filter,
     ...(options || {}),
     userid: userid,
    },
  });
}




